﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Halfpipe.Data.Repository;

namespace Halfpipe.Data.Service
{
    /// <summary>
    /// Provides basic CRUD operations for services with no special features
    /// Basically a pass-through to the repository
    /// </summary>
    public abstract class CrudService<TEntity> where TEntity : class
    {
        protected IRepository<TEntity> Repository { get; set; }

        public void Delete(TEntity existingEntity)
        {
            Repository.Delete(existingEntity);
        }

        public void DeleteAll()
        {
            Repository.DeleteAll();
        }

        public virtual TEntity Insert(TEntity newEntity)
        {
            return Repository.Insert(newEntity);
        }

        public virtual IQueryable<TEntity> SelectAll()
        {
            return Repository.SelectAll();
        }

        public TEntity Update(TEntity existingEntity)
        {
            return Repository.Update(existingEntity);
        }

        protected CrudService(IRepository<TEntity> repository)
        {
            this.Repository = repository;
        }
    }
}